package dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree;


import dk.mirasola.systemtraining.bridgewidgets.shared.model.Distribution;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.Seat;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree.shape.ShapeType;

public final class ShapeTypeDistributionFilter extends DistributionFilterGroupItem {
    private Seat seat = Seat.NORTH;
    private ShapeType shapeType = ShapeType.SHAPE_TYPE_4333;

    public Seat getSeat() {
        return seat;
    }

    public void setSeat(Seat seat) {
        if (seat == null)
            throw new IllegalArgumentException("null isn't legal");
        this.seat = seat;
    }

    public ShapeType getShapeType() {
        return shapeType;
    }

    public void setShapeType(ShapeType shapeType) {
        if (shapeType == null) {
            throw new NullPointerException();
        }
        this.shapeType = shapeType;
    }

    protected boolean matchesInternal(Distribution distribution) {
        return getShapeType().matches(distribution.getHand(seat));
    }

    @Override
    public boolean isCopy(GroupItem groupItem) {
        if (!super.isCopy(groupItem)) return false;
        if (!(groupItem instanceof ShapeTypeDistributionFilter)) return false;

        ShapeTypeDistributionFilter that = (ShapeTypeDistributionFilter) groupItem;
        return seat == that.seat && shapeType.equals(that.shapeType);
    }

    @Override
    public ShapeTypeDistributionFilter copy() {
        ShapeTypeDistributionFilter copy = new ShapeTypeDistributionFilter();
        copy.setInverted(getInverted());
        copy.seat = this.seat;
        copy.shapeType = this.shapeType;
        return copy;
    }
}
